package com.ruoyi.web.controller.news.api;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.domain.news.NewsPictureInfo;
import com.ruoyi.system.domain.news.query.NewsPictureInfoQuery;
import com.ruoyi.system.domain.news.vo.NewsPictureInfoVo;
import com.ruoyi.system.service.news.NewsPictureInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/news/newsPictureInfo")
@Api(value = "newsPictureInfoApiController", tags  = "图片新闻Api")
public class NewsPictureInfoApiController extends BaseController {

	@Resource
	private NewsPictureInfoService newsPictureInfoService;

	@ApiOperation(value = "获取单个图片新闻信息", notes = "获取单个图片新闻信息")
	@GetMapping("/getById")
	public R<NewsPictureInfo> getById(@RequestParam(value = "id") Long id) {
		NewsPictureInfoQuery newsPictureInfoQuery = new NewsPictureInfoQuery();
		newsPictureInfoQuery.setId(id);
		List<NewsPictureInfoVo> newsPictureInfoList = newsPictureInfoService.getNewsPictureInfoList(newsPictureInfoQuery);
		if (newsPictureInfoList!=null&&newsPictureInfoList.size()>0) {
			return R.ok(newsPictureInfoList.get(0));
		} else {
			return R.fail("数据不存在");
		}
	}

	@ApiOperation(value = "获取图片新闻信息列表")
	@PostMapping(value = "/list")
	public R<PageInfo<NewsPictureInfoVo>> list(@RequestBody NewsPictureInfoQuery newsPictureInfoQuery) {
        newsPictureInfoQuery.setIsEnable("1");
		List<NewsPictureInfoVo> newsPictureInfoList = newsPictureInfoService.getNewsPictureInfoList(newsPictureInfoQuery);
		return R.ok(new PageInfo<>(newsPictureInfoList));
	}
}
